from functools import reduce

if __name__ == '__main__':
    l = [1, 2, 3, 4, 5, 6, 7, 8, 9]

    # 计算 列表中所欲元素之和
    total = sum(l)
    print(total)

    total = 0
    for i in l:
        total += i
    print(total)

    # 使用 reduce 归并
    total = reduce(lambda i, j: i + j, l)
    print(total)

    # 可以设置归并的初始值
    init = reduce(lambda i, j: i + j, l, 10)
    print(init)
